<%@ page pageEncoding="utf-8"%> 
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>

<%
	request.setAttribute("layout","main.jsp");
	request.setAttribute("page_title","温岭选课系统-学生列表");
	List<Hashtable<String, String>> student_list = (List<Hashtable<String, String>>) session.getAttribute("NewStudentList");
	Iterator<Hashtable<String, String>> student_it = null;
	String coursename = request.getParameter("coursename");
	String courseId = request.getParameter("courseId");
	if(coursename == null)
		coursename = (String)session.getAttribute("coursename");
	if(courseId == null)
		courseId = (String)session.getAttribute("courseId");
	
	System.out.println("coursename:"+coursename);
	String   usertype   =   (String)session.getAttribute("userType");
	String studentname = (String)session.getAttribute("studentname");
	String grade = (String)session.getAttribute("grade");
%>

<link href="css/jquery.ui.tabs.css" rel="stylesheet">
<link href="css/jquery.ui.theme.css" rel="stylesheet">
<script src="js/jquery-1.5.2.min.js"></script>
<script src="js/jquery-ui-1.8.11.custom.min.js"></script>
<script src="js/jquery.ui.tabs.js"></script>
<script type="text/javascript" src="js/popup.js"></script>

<script type="text/javascript">
	
	function selectcourse(courseId,studentId,coursename){
		   $.ajax({
				url: base_path+"Admin/select.do",
				type: "POST",
				data: {"courseId":courseId,"studentId":studentId},
				beforeSend: function(XMLHttpRequest){
					//alert(courseId);
					return confirm("确定选修《"+coursename+"》吗?");
				},
				success: function(data, textStatus){
					if(data!=null && data!=""){
						alert(data);
					}else{ 
						alert("恭喜你，选课成功！");
					}
				},
				complete: function(XMLHttpRequest, textStatus){

					window.location.href=base_path+"Admin/selectdetail.do?courseId="+courseId;
				},
				error: function(){
					alert("网络异常，请重试！");
				}
			});
	   }
</script>

<div style="width:100%; margin:1px;text-align:center;margin-top:10px;margin-bottom:50px;">
 	<p style="border:0;font-size:14px;padding-bottom:0;">
  		<b>增加课程《<%=coursename %>》选课名单</b>
	</p>
	<form action="Search/searchStudent.do?courseId=<%=courseId %>&coursename=<%=coursename %>" method="post">
  		<table  style="border:0px solid gray;align:middle;width:50%;margin-left:25%; margin-bottom:20px">
  			<tr>
  				<td>学生姓名</td>
  				<td>
  					<input type=text style="width:160px;" name="studentname"/>
  				</td>
  				<td>&nbsp;&nbsp;年级</td>
  				<td>
  					<select style="width:160px;" name="grade">
 					<% if(grade!=null && grade.trim().equalsIgnoreCase("全部")){%>
 						<option value="全部" selected>全部</option>
 					<% }else {%>
 						<option value="全部">全部</option>
 					<% }if(grade!=null && grade.trim().equalsIgnoreCase("高一年级")){%>
 						<option value="高一" selected>高一年级</option>
 					<% }else {%>
 						<option value="高一">高一年级</option>
 					<% }if(grade!=null && grade.trim().equalsIgnoreCase("高二年级")){%>
 						<option value="高二" selected>高二年级</option>
 					<% }else {%>
 						<option value="高二">高二年级</option>
 					<%} if(grade!=null && grade.trim().equalsIgnoreCase("高三年级")){%>
 						<option value="高三" selected>高三年级</option>
 					<%} else {%>
 						<option value="高三">高三年级</option>
 						<%} %>
 					</select>
  				</td>
  				<td><input type="submit" value="查询"/></td>
  			</tr>
  		</table>
  </form>
  <table   style="border:1px solid gray;margin-left:10%;width:80%;">
    <tbody>
              <tr height="32" bgcolor="#f0f0f0">
				   <td align="center" width="7%">学号</td>
				   <td align="center" width="8%">姓名</td>
				   <td align="center" width="8%">班级</td>
				   <td align="center" width="10%">操作</td>
              </tr>
              <%
              	if(student_list != null)
              	{
              		student_it = student_list.iterator();
		        	while(student_it.hasNext())
					{
						Hashtable<String, String> studentlist_hash  = student_it.next();
			 %>
			  	<tr height="25" bgcolor="#ffffff">
		            <td align="center"><%=studentlist_hash.get("no") %></td>
			  		<td align="center"><%=studentlist_hash.get("name") %></td>
		            <td align="center"><%=studentlist_hash.get("grade") %></td>
		            <td align="center">
			          <a href="javascript:selectcourse(<%=courseId%>,<%=studentlist_hash.get("Id") %>,'<%=coursename %>')"  class="approve" >选课</a>
		            </td>
		         </tr>
			  <%} }%>
      </tbody>
    </table>
</div>
